package org.jeecg.modules.solitaire_app.control.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.solitaire_app.app.entity.VO.HomeResultVO;
import org.jeecg.modules.solitaire_app.app.entity.YsyOilType;
import org.jeecg.modules.solitaire_app.app.entity.YsyRefinery;
import org.jeecg.modules.solitaire_app.app.query.RefineryPriceQuery;
import org.jeecg.modules.solitaire_app.control.entity.YsyControlKey;
import org.jeecg.modules.solitaire_app.control.entity.YsyPriceList;
import org.jeecg.modules.solitaire_app.control.entity.YsyRefineryPrice;
import org.jeecg.modules.solitaire_app.control.mapper.YsyControlKeyMapper;
import org.jeecg.modules.solitaire_app.control.service.IYsyControlKeyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 终端密钥
 * @Author: jeecg-boot
 * @Date: 2024-01-15
 * @Version: V1.0
 */
@Service
@DS("ysy_db")
public class YsyControlKeyServiceImpl extends ServiceImpl<YsyControlKeyMapper, YsyControlKey> implements IYsyControlKeyService {

    @Autowired
    private YsyControlKeyMapper ysyControlKeyMapper;

    @Override
    public Result<PageInfo<HomeResultVO>> getRefineryPrice(RefineryPriceQuery refineryPriceQuery) {
        Result<PageInfo<HomeResultVO>> result = new Result<>();
        try {
            PageHelper.startPage(refineryPriceQuery.getPageNo(), refineryPriceQuery.getPageSize());
            List<HomeResultVO> homeResultVOS = ysyControlKeyMapper.getRefineryPrice(refineryPriceQuery);
            PageInfo pageInfo = new PageInfo(homeResultVOS);
            result.setSuccess(true);
            result.setCode(200);
            result.setResult(pageInfo);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setMessage("服务器响应失败");
            result.setCode(500);
            result.setSuccess(false);
            return result;
        }
    }

    @Override
    public Result<List<YsyRefinery>> getRefineryList() {
        Result<List<YsyRefinery>> result = new Result<>();
        try {
            List<YsyRefinery> refineries = ysyControlKeyMapper.getRefineryList();
            result.setCode(200);
            result.setResult(refineries);
            result.setSuccess(true);
            return result;
        }catch (Exception e){
            log.error(e.getMessage(), e);
            result.setCode(500);
            result.setSuccess(false);
            result.setMessage("服务器响应失败");
            return result;
        }
    }

    @Override
    public Result<List<YsyOilType>> getOilTypeList(Integer type) {
        Result<List<YsyOilType>> result = new Result<>();
        try {
            List<YsyOilType> refineries = ysyControlKeyMapper.getOilTypeList(type);
            result.setCode(200);
            result.setResult(refineries);
            result.setSuccess(true);
            return result;
        }catch (Exception e){
            log.error(e.getMessage(), e);
            result.setCode(500);
            result.setSuccess(false);
            result.setMessage("服务器响应失败");
            return result;
        }
    }
}
